home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / c / showbox.com / SHOWBOX.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1993-06-04  |  16.3 KB  |  806 lines

  1.  
  2.  
  3. /*
  4.  *
  5.     showbox.cpp
  6.  
  7.     code to support the class 'Box'
  8.  *
  9.  *        $Revision:   1.7  $
  10.  *
  11.  *
  12.  *        $Log:   C:/pbmdtsts/library/showbox.cpv  $
  13.  *  
  14.  *     Rev 1.7   03 Jun 1993 14:25:36   C_BAKER
  15.  *  un-defined the HEAPTRACE define.
  16.  *  
  17.  *     Rev 1.6   02 Jun 1993 11:55:16   C_BAKER
  18.  *  Many changes.
  19.  *  Changes include;
  20.  *      removal of the concept of having a list of malloc'd
  21.  *      storage.  The list was being overrun when multiple
  22.  *      calls to redraw were executed.
  23.  *      
  24.  *      Instead of using malloc and free there are now functions
  25.  *      GetStorage and KillStorage which allow greater debugging
  26.  *      ability.
  27.  *      
  28.  *      
  29.  *  
  30.  *     Rev 1.5   27 May 1993 14:31:02   C_BAKER
  31.  *  Removed the overloaded ErrorBox constructor and made the
  32.  *  'ContinuousFlag' variable globel in mces.h.
  33.    
  34.       Rev 1.4   27 May 1993 13:24:20   C_BAKER
  35.    Added overloaded ErrorBox constructor which takes a variable
  36.    named 'Continuous'.  This flag determines if the function will
  37.    wait for keyboard input or just pause on error.
  38.    
  39.       Rev 1.3   20 May 1993 11:07:02   C_BAKER
  40.    
  41.    This revision appears to clear up the problem of the
  42.    heap not being restored properly when the class is destroyed.
  43.    
  44.       Rev 1.2   19 May 1993 15:19:48   C_BAKER
  45.    Fixed problems with malloc/free.
  46.    
  47.       Rev 1.1   19 May 1993 13:26:48   C_BAKER
  48.    Added subclass 'ErrorBox'.
  49.    Having trouble with running out of heap space due to
  50.    fragmented mallocs and frees.
  51.    
  52.       Rev 1.0   10 May 1993 14:52:14   C_BAKER
  53.    Initial revision.
  54.  *
  55. */
  56.  
  57. #include <string.h>
  58. #include <stdlib.h>
  59. #include "mces.h"
  60. #include "screen.h"
  61.  
  62. char ShowMsgBox( char * Msg, int ErrOrPrompt );
  63. void NextPos( int &, int &, int );
  64. void ErrorTones(void);
  65.  
  66. uchar * GetStorage( unsigned size );
  67. void KillStorage( char * tstore );
  68.  
  69. // #define HEAPREPORT
  70.  
  71. // #define HEAPTRACE
  72.  
  73. // #define    DONOTHING
  74.  
  75.  
  76. #ifdef HEAPREPORT
  77.  
  78. typedef struct {
  79.     int count;
  80.     long size;
  81. } THEAP;
  82.  
  83. long HeapSize(THEAP & theap);
  84. #endif
  85.  
  86. #include "showbox.hpp"
  87.  
  88. Box :: Box ( char * Title, char * Msg, int ReqXpos, int ReqYpos, uchar ReqAttrib )
  89. {
  90. #ifdef DONOTHING
  91.     printf("\nBox message is %s", Msg );
  92.     return;
  93. #endif
  94.  
  95.     BoxWidth = 0;
  96.  
  97.     AbsPos = 1;
  98.  
  99.     // set all message addresses to 0
  100.     for (BreakLineInx = 0; BreakLineInx < 20; BreakLineInx++)
  101.         Brokenlines[BreakLineInx] = 0;
  102.  
  103.     Xpos = ReqXpos; Ypos = ReqYpos; Attrib = ReqAttrib;
  104.  
  105.     BaseScreen = (unsigned char far *) 0xb8000000;
  106.  
  107.     LMsg = GetStorage(strlen(Msg)+5);
  108.  
  109.     if (!LMsg)
  110.     {
  111.         printf("\nUnable to allocate storage at box constructor\n"
  112.             "File %s, line %u\n"
  113.             "Press any key to continue",__FILE__, __LINE__);
  114.         while (!kbhit());
  115.         getchar();
  116.     }
  117.  
  118.     LTitle = GetStorage(strlen(Title)+5);
  119.     if (!LTitle)
  120.     {
  121.         printf("Could not allocate storage during creation of box\n"
  122.             "File %s, line %u\n"
  123.             "Press any key to continue",__FILE__, __LINE__);
  124.         while (!kbhit());
  125.         getchar();
  126.         return;
  127.     }
  128.  
  129.     strcpy( LTitle, Title );
  130.  
  131.     // if a system configuration verify error
  132.     if (Msg[0] == 'S' && Msg[1] == 'V')
  133.         strcpy( LMsg, &Msg[2] );
  134.     else
  135.         strcpy( LMsg, Msg );
  136.  
  137.     BreakupMessage();        // determines box with
  138.  
  139.     SaveScreenArea();
  140.  
  141.     BuildTheBox();
  142.  
  143.     FillTheBox();
  144.  
  145.     MessageInBox();
  146.  
  147.     TitleOnBox();
  148.  
  149.     ShadeTheBox();
  150.  
  151.     // free allocated storage
  152.     for (BreakLineInx = 0; Brokenlines[BreakLineInx]; BreakLineInx++)
  153.     {
  154.         KillStorage ( Brokenlines[BreakLineInx] );
  155.         Brokenlines[BreakLineInx] = 0;
  156.     }
  157. }
  158.  
  159. Box :: Box ( char * Title, char * Msg, uchar ReqAttrib )
  160. {
  161. #ifdef DONOTHING
  162.     printf("\nBox message is %s", Msg );
  163.     return;
  164. #endif
  165.  
  166.     BoxWidth = 0;
  167.  
  168.     AbsPos = 0;
  169.  
  170.     NextPos(Xpos, Ypos, 3);
  171.     
  172.     // set all message addresses to 0
  173.     for (BreakLineInx = 0; BreakLineInx < 20; BreakLineInx++)
  174.         Brokenlines[BreakLineInx] = 0;
  175.  
  176.     Attrib = ReqAttrib;
  177.  
  178.     BaseScreen = (unsigned char far *) 0xb8000000;
  179.  
  180.     LMsg = GetStorage(strlen(Msg)+5);
  181.     if (!LMsg)
  182.     {
  183.         printf("\nUnable to allocate storage at box constructor\n"
  184.             "File %s, line %u\n"
  185.             "Press any key to continue",__FILE__, __LINE__);
  186.         while (!kbhit());
  187.         getchar();
  188.     }
  189.  
  190.     LTitle = GetStorage(strlen(Title)+5);
  191.     if (!LTitle)
  192.     {
  193.         printf("Could not allocate storage during creation of box\n"
  194.             "File %s, line %u\n"
  195.             "Press any key to continue",__FILE__, __LINE__);
  196.         while (!kbhit());
  197.         getchar();
  198.         return;
  199.     }
  200.  
  201.     strcpy( LTitle, Title );
  202.  
  203.     // if a system configuration verify error
  204.     if (Msg[0] == 'S' && Msg[1] == 'V')
  205.         strcpy( LMsg, &Msg[2] );
  206.     else
  207.         strcpy( LMsg, Msg );
  208.  
  209.     BreakupMessage();        // determines box with
  210.  
  211.     SaveScreenArea();
  212.  
  213.     BuildTheBox();
  214.  
  215.     FillTheBox();
  216.  
  217.     MessageInBox();
  218.  
  219.     TitleOnBox();
  220.  
  221.     ShadeTheBox();
  222.  
  223.     // free allocated storage
  224.     for (BreakLineInx = 0; Brokenlines[BreakLineInx]; BreakLineInx++)
  225.     {
  226.         KillStorage ( Brokenlines[BreakLineInx] );
  227.         Brokenlines[BreakLineInx] = 0;
  228.     }
  229. }
  230.  
  231.  
  232. Box :: Box ( char * Title, int ReqXpos, int ReqYpos, uchar ReqAttrib )
  233. {
  234. #ifdef DONOTHING
  235.     printf("\nBox message is NO-MESSAGE" );
  236.     return;
  237. #endif
  238.     BoxWidth = 0;
  239.  
  240.     SavedScreenArea = 0;
  241.  
  242.     AbsPos = 1;
  243.  
  244.     // set all message addresses to 0
  245.     for (BreakLineInx = 0; BreakLineInx < 20; BreakLineInx++)
  246.         Brokenlines[BreakLineInx] = 0;
  247.  
  248.     Xpos = ReqXpos; Ypos = ReqYpos; Attrib = ReqAttrib;
  249.  
  250.     BaseScreen = (unsigned char far *) 0xb8000000;
  251.  
  252.     setmem( Brokenlines, sizeof(Brokenlines), 0 );
  253.  
  254.     LTitle = GetStorage(strlen(Title)+5);
  255.     if (!LTitle)
  256.     {
  257.         printf("Could not allocate storage during creation of box\n"
  258.             "File %s, line %u\n"
  259.             "Press any key to continue",__FILE__, __LINE__);
  260.         while (!kbhit());
  261.         getchar();
  262.         return;
  263.     }
  264.  
  265.     strcpy( LTitle, Title );
  266.  
  267.     LMsg = 0;
  268.  
  269.     // free allocated storage
  270.     for (BreakLineInx = 0; Brokenlines[BreakLineInx]; BreakLineInx++)
  271.     {
  272.         KillStorage ( Brokenlines[BreakLineInx] );
  273.         Brokenlines[BreakLineInx] = 0;
  274.     }
  275. }
  276.  
  277. Box :: ~Box()
  278. {
  279. #ifdef DONOTHING
  280.     return;
  281. #endif
  282.     if (SavedScreenArea)
  283.     {
  284.         RestoreScreenArea();
  285.         KillStorage( SavedScreenArea );
  286.     }
  287.  
  288.     if (!AbsPos)
  289.         NextPos(Xpos, Ypos, -3);
  290.  
  291.     KillStorage( LMsg );
  292.     KillStorage( LTitle );
  293.  
  294. }
  295.  
  296. void Box :: SaveScreenArea(void)
  297. {
  298.     SavedScreenArea = GetStorage(4000);    // one screen's worth char & attr
  299.  
  300.     if (!SavedScreenArea)
  301.     {
  302.         printf("Unable to allocate storage to save the screen area\n"
  303.             "File %s, line %u\n"
  304.             "Press any key to continue",__FILE__, __LINE__);
  305.         while (!kbhit());
  306.         getchar();
  307.     }
  308.  
  309.  
  310.     char *ScrnPtr = SavedScreenArea;
  311.  
  312.     for (int y = 0; y < BoxHite + 1; y++)
  313.         for (int x = 0; x < BoxWidth + 1; x++)
  314.         {
  315.             WorkScreen = BaseScreen + (Xpos + x) * 2 + (Ypos + y) * 160;
  316.             *ScrnPtr++ = *WorkScreen++;
  317.             *ScrnPtr++ = *WorkScreen++;
  318.         }
  319.  
  320. }
  321.  
  322. void Box :: RestoreScreenArea(void)
  323. {
  324.     char *ScrnPtr = SavedScreenArea;
  325.  
  326.     for (int y = 0; y < BoxHite + 1; y++)
  327.         for (int x = 0; x < BoxWidth + 1; x++)
  328.         {
  329.             WorkScreen = BaseScreen + (Xpos + x) * 2 + (Ypos + y) * 160;
  330.             *WorkScreen++ = *ScrnPtr++;
  331.             *WorkScreen++ = *ScrnPtr++;
  332.         }
  333.  
  334. }
  335.  
  336. void Box :: BuildTheBox(void)
  337. {
  338.  
  339.     WorkScreen = BaseScreen + Xpos * 2 + Ypos * 160;
  340.  
  341.     *WorkScreen++ = '╔';
  342.     *WorkScreen++ = Attrib;
  343.  
  344.     for (int x = 1; x < BoxWidth - 1; x++)
  345.     {
  346.         *WorkScreen++ = '═';
  347.         *WorkScreen++ = Attrib;
  348.     }
  349.  
  350.     *WorkScreen++ = '╗';
  351.     *WorkScreen++ = Attrib;
  352.  
  353.     WorkScreen = BaseScreen + Xpos * 2 + (Ypos + BoxHite - 1) * 160;
  354.  
  355.     *WorkScreen++ = '╚';
  356.     *WorkScreen++ = Attrib;
  357.  
  358.     for ( x = 1; x < BoxWidth - 1; x++)
  359.     {
  360.         *WorkScreen++ = '═';
  361.         *WorkScreen++ = Attrib;
  362.     }
  363.  
  364.     *WorkScreen++ = '╝';
  365.     *WorkScreen++ = Attrib;
  366.  
  367.     for (int y = 1; y < BoxHite - 1; y++)
  368.     {
  369.         WorkScreen = BaseScreen + Xpos * 2 + (Ypos + y) * 160;
  370.         *WorkScreen++ = '║';
  371.         *WorkScreen++ = Attrib;
  372.  
  373.         WorkScreen = BaseScreen + Xpos * 2 + (BoxWidth - 1) * 2 + (Ypos + y) * 160;
  374.         *WorkScreen++ = '║';
  375.         *WorkScreen++ = Attrib;
  376.  
  377.     }
  378.  
  379. }
  380.  
  381. void Box :: MessageInBox(void)
  382. {
  383.     int inx;
  384.     char * p1;
  385.  
  386.     for ( inx = 0; Brokenlines[inx]; inx++ )
  387.     {
  388.         WorkScreen = BaseScreen + (Xpos + 2) * 2 + (Ypos + 2 + inx) * 160;
  389.  
  390.         for ( p1 = Brokenlines[inx]; *p1; p1++ )
  391.         {
  392.             *WorkScreen++ = *p1;
  393.             *WorkScreen++ = Attrib;
  394.         }
  395.     }
  396. }
  397.  
  398. void Box :: TitleOnBox(void)
  399. {
  400.     WorkScreen = BaseScreen + (Xpos + 2) * 2 + Ypos * 160;
  401.  
  402.     for ( char * p1 = LTitle; *p1; p1++ )
  403.     {
  404.         *WorkScreen++ = *p1;
  405.         *WorkScreen++ = Attrib;
  406.     }
  407. }
  408.  
  409. void Box :: FillTheBox(void)
  410. {
  411.     for (int y = 1; y < BoxHite - 1; y++ )
  412.         for (int x = 1; x < BoxWidth - 1; x++)
  413.         {
  414.             WorkScreen = BaseScreen + (Xpos + x) * 2 + (Ypos + y) * 160;
  415.             *WorkScreen++ = '░';
  416.             *WorkScreen = Attrib;
  417.         }
  418. }
  419.  
  420. void Box :: ShadeTheBox(void)
  421. {
  422.     for (int y = 1; y <= BoxHite; y++)
  423.     {
  424.         WorkScreen = BaseScreen + (Xpos + BoxWidth ) * 2 + (Ypos + y) * 160;
  425.         *(WorkScreen + 1) = 8;    // set attribute
  426.     }
  427.  
  428.     for (int x = Xpos + 1; x <= Xpos + BoxWidth; x++ )
  429.     {
  430.         WorkScreen = BaseScreen + x * 2 + (Ypos + BoxHite) * 160;
  431.         *(WorkScreen + 1) = 8;    // set attribute
  432.     }
  433.  
  434. }
  435.  
  436. void Box :: BreakupMessage(void)
  437. {
  438.  
  439.     int BreakLineInx;
  440.     char *pWork;        // holds position during long string break-up
  441.     int MsgLen;
  442.  
  443.     BreakLineInx = 0;
  444.     pWork = LMsg;
  445.  
  446.     do
  447.     {
  448.         Brokenlines[BreakLineInx] = GetStorage(100);
  449.         if (Brokenlines[BreakLineInx] == NULL)
  450.         {
  451.             printf("\nUnable to allocate storage to break up message\n"
  452.             "File %s, line %u\n"
  453.             "Press any key to continue",__FILE__, __LINE__);
  454.             while (!kbhit());
  455.             getchar();
  456.         }
  457.  
  458.         setmem( Brokenlines[BreakLineInx], 60, 0 );
  459.  
  460.         // put as big as piece of the message as possible
  461.         // into the malloc'd storage
  462.         BreakLine( BreakLineInx, &pWork );
  463.  
  464.         MsgLen = strlen( pWork );
  465.         BreakLineInx++;
  466.  
  467.     } while( MsgLen );
  468.  
  469.     BoxHite = BreakLineInx + 4;
  470.  
  471.     BoxWidth = max ( BoxWidth, strlen( LTitle ) + 4 );
  472. }
  473.  
  474. /**********************************************************************
  475. *  BoxWidth is set to 0 before calling
  476. *  to break up long lines
  477. *
  478. *if length of LMsg <= 56 && !(strchr(LMsg, '\n') )
  479. *    copy LMsg to element of buffer[]
  480. *    set return pointer to end of LMsg
  481. *    set BoxWidth to length of LMsg + 4
  482. *    return
  483. *
  484. *if strchr( LMsg, '\n' )
  485. *    if the '\n' is lte 56 chars from beginning of LMsg
  486. *        copy from beginning of LMsg up to the '\n' 
  487. *            into element of buffer
  488. *        set BoxWidth to the max of BoxWidth or numchars
  489. *            from beginning of LMSG up to current position
  490. *        set return pointer to position of '\n' + 1
  491. *        return
  492. *    else
  493. *        step back from '\n' until a space is encountered
  494. *        and the pointer is lte LMsg + 56
  495. *        set BoxWidth to the max of BoxWidth or numchars
  496. *            from beginning of LMSG up to current position
  497. *        set return pointer to current position + 1
  498. *        return
  499. *    
  500. * remaining condition is that the string has no '\n' in it
  501. * and it is longer then 56 chars
  502. *
  503. *set pointer to LMsg + 56
  504. *step back until a space is reached
  505. *copy from LMsg up to current position
  506. *set BoxWidth to the max of BoxWidth or numchars
  507. *    from beginning of LMSG up to current position
  508. *set return pointer to current position + 1
  509. *
  510. *end of function to break up long lines
  511. ************************************************************/
  512.  
  513. void Box :: BreakLine ( int inx, char ** FirstPtr )
  514. {
  515.     char * CurrentPosition;
  516.     int LMLen;
  517.  
  518.     LMLen = strlen(*FirstPtr);
  519.  
  520.     if ( LMLen <= 56 && !strchr(*FirstPtr,'\n') )
  521.     {
  522.         strcpy( Brokenlines[inx], *FirstPtr );
  523.         *FirstPtr = LMLen + *FirstPtr;
  524.         BoxWidth = max(BoxWidth, LMLen + 4);
  525.         return;
  526.     }
  527.  
  528.     if ( (CurrentPosition = strchr( *FirstPtr, '\n')) != 0 )
  529.     {
  530.         if ( (CurrentPosition - *FirstPtr) <= 56 )
  531.         {
  532.             strncpy(Brokenlines[inx], *FirstPtr, CurrentPosition - *FirstPtr );
  533.             BoxWidth = max(BoxWidth, CurrentPosition - *FirstPtr + 4 );
  534.             *FirstPtr = CurrentPosition + 1;
  535.             return;
  536.         }
  537.         else
  538.         {
  539.             while (*CurrentPosition != ' ' || (CurrentPosition - *FirstPtr) > 56 )
  540.                 CurrentPosition--;
  541.  
  542.             strncpy(Brokenlines[inx], *FirstPtr, CurrentPosition - *FirstPtr );
  543.             BoxWidth = max(BoxWidth, CurrentPosition - *FirstPtr + 4 );
  544.             *FirstPtr = CurrentPosition + 1;
  545.             return;
  546.         }
  547.     }
  548.  
  549. // remaining condition is that the string has no '\n' in it
  550. // and it is longer then 56 chars
  551.  
  552.     CurrentPosition = *FirstPtr + 56;
  553.     while (*CurrentPosition != ' ' )
  554.         CurrentPosition--;
  555.  
  556.     strncpy(Brokenlines[inx], *FirstPtr, CurrentPosition - *FirstPtr );
  557.  
  558.     BoxWidth = max(BoxWidth, CurrentPosition - *FirstPtr + 4 );
  559.  
  560.     *FirstPtr = CurrentPosition + 1;
  561.  
  562. }
  563.  
  564. void Box :: Redraw( char * Msg )
  565. {
  566. #ifdef DONOTHING
  567.     printf("\nRedraw message is %s", Msg );
  568.     return;
  569. #endif
  570.  
  571.     // set all message addresses to 0
  572.     for (BreakLineInx = 0; BreakLineInx < 20; BreakLineInx++)
  573.         Brokenlines[BreakLineInx] = 0;
  574.  
  575.     if ( strlen(Msg) <= strlen(LMsg) )
  576.     {
  577.         setmem( LMsg, strlen(LMsg), '░' );
  578.  
  579.         BreakupMessage();        // determines box with
  580.         MessageInBox();
  581.         for (BreakLineInx = 0; Brokenlines[BreakLineInx]; BreakLineInx++)
  582.         {
  583.             KillStorage ( Brokenlines[BreakLineInx] );
  584.             Brokenlines[BreakLineInx] = 0;
  585.         }
  586.  
  587.         strcpy( LMsg, Msg );
  588.  
  589.         BreakupMessage();        // determines box with
  590. //        FillTheBox();
  591.         MessageInBox();
  592.         // free allocated storage
  593.         for (BreakLineInx = 0; Brokenlines[BreakLineInx]; BreakLineInx++)
  594.         {
  595.             KillStorage ( Brokenlines[BreakLineInx] );
  596.             Brokenlines[BreakLineInx] = 0;
  597.         }
  598.         return;
  599.     }
  600.  
  601.     if (SavedScreenArea)
  602.     {
  603.         RestoreScreenArea();
  604.         KillStorage( SavedScreenArea );
  605.     }
  606.  
  607.     KillStorage(LMsg);
  608.  
  609.     LMsg = GetStorage(strlen(Msg)+5);
  610.  
  611.     if (!LMsg)
  612.     {
  613.         printf("\nCould not allocate storage during creation of box\n"
  614.             "File %s, line %u\n"
  615.             "Press any key to continue",__FILE__, __LINE__);
  616.         while (!kbhit());
  617.         getchar();
  618.         return;
  619.     }
  620.  
  621.     strcpy( LMsg, Msg );
  622.  
  623.     BreakupMessage();        // determines box with
  624.  
  625.     SaveScreenArea();
  626.  
  627.     BuildTheBox();
  628.  
  629.     FillTheBox();
  630.  
  631.     MessageInBox();
  632.  
  633.     TitleOnBox();
  634.  
  635.     ShadeTheBox();
  636.  
  637.     // free allocated storage
  638.     for (BreakLineInx = 0; Brokenlines[BreakLineInx]; BreakLineInx++)
  639.     {
  640.         KillStorage ( Brokenlines[BreakLineInx] );
  641.         Brokenlines[BreakLineInx] = 0;
  642.     }
  643. }
  644.  
  645. void NextPos( int &xpos, int &ypos, int incdec )
  646. {
  647.     static xp, yp, firsttime;
  648.  
  649.     if (!xpos && !ypos && !incdec)
  650.     {
  651.         firsttime = 0;
  652.         return;
  653.     }
  654.  
  655.     if (!firsttime)
  656.     {
  657.         xp = 10;
  658.         yp = 5;
  659.         firsttime++;
  660.         xpos = xp += incdec;
  661.         ypos = yp += incdec;
  662.         return;
  663.     }
  664.  
  665.     if (xp >= 10)
  666.         xpos = xp += incdec;
  667.     if (yp >= 5)
  668.         ypos = yp += incdec;
  669. }
  670.  
  671. ErrorBox :: ErrorBox( char * Msg )
  672.  : Box( "ERROR",Msg,BRIGHTWHITEFORGROUND + REDBACKGROUND )
  673. {
  674.     char * lline = GetStorage(200);
  675.  
  676.     if (!lline)
  677.     {
  678.         printf("\nTrouble allocating storage at %s %u",
  679.             __FILE__, __LINE__);
  680.         while (!kbhit());
  681.         getch();
  682.     }
  683.  
  684.     strcpy(lline,Msg);
  685.  
  686.     if (!ContinuousFlag)
  687.         strcat(lline,"\n\nHit any key to continue");
  688.  
  689.     Redraw( lline );
  690.  
  691.     ErrorTones();
  692.  
  693.     if (!ContinuousFlag)
  694.     {
  695.         while (!kbhit());
  696.         getch();
  697.     }
  698.     else
  699.         sleep(3);
  700.  
  701.     KillStorage (lline);
  702. }
  703.  
  704. // #define WAIT
  705.  
  706. uchar * GetStorage( unsigned size )
  707. {
  708.     char * tstore;
  709.  
  710. #ifdef HEAPREPORT
  711.     THEAP Lheap = {0,0};
  712.  
  713.     if( HeapSize( Lheap ) == -1L )
  714.     {
  715.         printf("\nHeap error");
  716.         while (!kbhit());
  717.         getch();
  718.     }
  719.  
  720.     printf("\nHeap count at getstorage1 = %u, heap size = %lu",Lheap.count, Lheap.size );
  721. #ifdef WAIT
  722.     while(!kbhit());
  723.     getch();
  724. #endif
  725. #endif
  726.  
  727. //    tstore = (char *) malloc( size );
  728.     tstore = new uchar[ size ];
  729.  
  730. #ifdef HEAPTRACE
  731.     printf("\nAllocating %p\tsize %u", tstore, size );
  732. #endif
  733.  
  734.     if (!tstore)
  735.     {
  736.         printf("\nUnable to allocate storage");
  737.         while (!kbhit());
  738.         getch();
  739.     }
  740.  
  741. #ifdef HEAPREPORT
  742.     THEAP mheap = {0,0};
  743.  
  744.     if( HeapSize( mheap ) == -1L )
  745.     {
  746.         printf("\nHeap error");
  747.         while (!kbhit());
  748.         getch();
  749.     }
  750.  
  751.     printf("\nHeap count at getstorage2 = %u, heap size = %lu",mheap.count, mheap.size );
  752. #ifdef WAIT
  753.     while(!kbhit());
  754.     getch();
  755. #endif
  756. #endif
  757.  
  758.     return tstore;
  759.  
  760. }
  761.  
  762. void KillStorage( char * tstore )
  763. {
  764. #ifdef HEAPREPORT
  765.     THEAP Lheap = {0,0};
  766.     if( HeapSize( Lheap ) == -1L )
  767.     {
  768.         printf("\nHeap error");
  769.         while (!kbhit());
  770.         getch();
  771.     }
  772.  
  773.     printf("\nHeap count at killstorage1 = %u, heap size = %lu",Lheap.count, Lheap.size );
  774. #ifdef WAIT
  775.     while(!kbhit());
  776.     getch();
  777. #endif
  778. #endif
  779.  
  780. #ifdef HEAPTRACE
  781.     printf("\nFreeing %p", tstore );
  782. #endif
  783.  
  784. //    free( tstore );
  785.     delete( tstore );
  786.  
  787. #ifdef HEAPREPORT
  788.     Lheap.size = 0;
  789.     Lheap.count = 0;
  790.  
  791.     if( HeapSize( Lheap ) == -1L )
  792.     {
  793.         printf("\nHeap error");
  794.         while (!kbhit());
  795.         getch();
  796.     }
  797.  
  798.     printf("\nHeap count at killstorage2 = %u, heap size = %lu",Lheap.count, Lheap.size );
  799. #ifdef WAIT
  800.     while(!kbhit());
  801.     getch();
  802. #endif
  803. #endif
  804.  
  805. }
  806.